package com.pic.mgt.monitor.check;

import com.pic.mgt.monitor.WrongUnitFormatException;

public class MsgFilenameLenCheck implements FormatCheck {
	private int[] transactionFilenameLenArray;
	private String transOkMsgConfirmationSuffix;
	
	private int transOkMsgConfirmationSuffixLen;

	@Override
	public void check(String confirmationFilename)
													throws WrongUnitFormatException {
		int confirmationFilenameLen = confirmationFilename.length();
		
		boolean msgFilenameLenIncorrect = true;
		for (int transactionFilenameLen : transactionFilenameLenArray) {
			int suffixLen = confirmationFilenameLen - transactionFilenameLen;
			
			if (suffixLen == transOkMsgConfirmationSuffixLen) {
				msgFilenameLenIncorrect = false;
			}
			// --- 刪除 else 區塊 BEGIN ---
			/*else {
				if (confirmationFilename.indexOf("_IRDD_") >= 0 &&
					suffixLen == (transOkMsgConfirmationSuffixLen + 11)) {
					msgFilenameLenIncorrect = false;
				}
			}*/
			// --- 刪除 else 區塊 END ---
		}
		
		if (msgFilenameLenIncorrect) {
			throw new WrongUnitFormatException(
					"Wrong confirmation filename length : '" + confirmationFilename + "'");
		}
	}

	// --- getter and setter ---
	
	public void setTransactionFilenameLenArray(int[] transactionFilenameLenArray) {
		this.transactionFilenameLenArray = transactionFilenameLenArray;
	}

	public void setTransOkMsgConfirmationSuffix(String transOkMsgConfirmationSuffix) {
		this.transOkMsgConfirmationSuffix = transOkMsgConfirmationSuffix;
		this.transOkMsgConfirmationSuffixLen = transOkMsgConfirmationSuffix.length();
	}	
}
